﻿using Deployment.Data.Deploy.Steps.Tasks;
using Deployment.Data.UI.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Deployment.Data.UI.Controls.Task
{
    /// <summary>
    /// Interaction logic for AddTaskControl.xaml
    /// </summary>
    public partial class AddTaskControl : AbstractDialogContentControl
    {
        public static readonly DependencyProperty EnvironmentsProperty =
            DependencyProperty.Register("Environments",
                typeof(Data.Environment.EnvironmentsFile),
                typeof(AddTaskControl));

        public static readonly DependencyProperty CurrentStepProperty =
            DependencyProperty.Register("CurrentStep",
                typeof(Data.Deploy.Steps.Step),
                typeof(AddTaskControl));

        public Data.Environment.EnvironmentsFile Environments
        {
            get { return (Data.Environment.EnvironmentsFile)GetValue(EnvironmentsProperty); }
            set { SetValueDp(EnvironmentsProperty, value); }
        }

        public Data.Deploy.Steps.Step CurrentStep
        {
            get { return (Data.Deploy.Steps.Step)GetValue(CurrentStepProperty); }
            set { SetValueDp(CurrentStepProperty, value); }
        }

        public event DependencyPropertyChangedEventHandler PropertyChanged;

        private void SetValueDp(DependencyProperty property, object value)
        {
            SetValue(property, value);
            if (PropertyChanged != null)
                PropertyChanged(this, new DependencyPropertyChangedEventArgs());
        }

        public AbstractTask TaskData
        {
            get { return EditorControl.DataContext as AbstractTask; }
        }

        public AddTaskControl()
        {
            InitializeComponent();
        }

        private void TypeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

        private void EditorControl_Loaded(object sender, RoutedEventArgs e)
        {
           
        }

        protected internal override bool isContentOk()
        {
            return (EditorControl.DataContext as AbstractTask).isContentOk;
        }

        private void EditorControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            //CurrentStep="{Binding ElementName=Control, Path=CurrentStep, UpdateSourceTrigger=PropertyChanged}"
            //Environments="{Binding ElementName=Control, Path=Environments, UpdateSourceTrigger=PropertyChanged}"
            EditorControl.CurrentStep = CurrentStep;
            EditorControl.Environments = Environments;
        }

        private void okContentCheckbox_Checked(object sender, RoutedEventArgs e)
        {
            ContentOk = okContentCheckbox.IsChecked == true ? true : false;
        }
    }
}
